<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 700px;
            margin: 100px auto;
            text-align: center;
            font-size: 15px;
            border-collapse: collapse;
        }

        th {
            height: 40px;
            background-color: blueviolet;
        }

        tr {
            height: 40px;
        }

        td {
            height: 40px;
            font-size: 13px;
            border-bottom: 1px solid rebeccapurple;
        }

        .bw {
            background-color: yellowgreen;
        }
    </style>
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>编号</th>
                <th>商品名称</th>
                <th>价格</th>
                <th>库存</th>
                <th>当日出售</th>
                <th>剩余</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>111</td>
                <td>西瓜</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
            <tr>
                <td>222</td>
                <td>苹果</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
            <tr>
                <td>333</td>
                <td>香蕉</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
            <tr>
                <td>444</td>
                <td>桃子</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
            <tr>
                <td>555</td>
                <td>石榴</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
            <tr>
                <td>666</td>
                <td>梨子</td>
                <td>11.5</td>
                <td>555</td>
                <td>15</td>
                <td>333</td>
            </tr>
        </tbody>
    </table>

    <script>
        const trs = document.querySelectorAll("tr");
        /* 
           需求：对每行绑定鼠标移入和移出事件
        */
        for (const tr of trs) {
            // onmouseover 鼠标移入
            tr.onmouseover = function () {
                this.className = 'bw';
            }

            // onmouseout 鼠标移出
            tr.onmouseout = function () {
                this.className = '';
            }
        }
    </script>
</body>

</html>